# Maintainer: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

_realname=cgns
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.3.0
pkgrel=4
pkgdesc="CFD General Notation System library and tools (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://cgns.github.io"
license=('spdx:Zlib')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-hdf5")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/CGNS/CGNS/archive/v${pkgver}.tar.gz)
sha256sums=('7709eb7d99731dea0dd1eff183f109eaef8d9556624e3fbc34dc5177afc0a032')

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    ${extra_config[@]} \
    -DCGNS_ENABLE_HDF5=ON \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}
  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake.exe --install .

  # license
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/license.txt \
  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
